package com.llho.core.dao.impl;

import java.util.List;

import org.hibernate.HibernateException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.llho.core.dao.ImageDAO;
import com.llho.core.domain.Image;
import com.llho.core.domain.Product;

public class ImageDAOImpl extends HibernateDaoSupport implements ImageDAO {

	@Override
	public Image getById(Long id) {
		Image kq = null;
		try{
			kq = (Image) getHibernateTemplate().get(Image.class, id);
		}catch(HibernateException e){
			e.printStackTrace();
		}
		return kq;
	}

	@Override
	public List<Image> getAll() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Image> getByProduct(Product entity) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void addNew(Image entity) {
		try{
			getHibernateTemplate().save(entity);
		}catch(HibernateException e){
			e.printStackTrace();
		}
	}

	@Override
	public void update(Image entity) {
		try{
			Image tmp = (Image) getHibernateTemplate().load(Image.class, entity.getId());
			getHibernateTemplate().update(tmp);
		}catch(HibernateException e){
			e.printStackTrace();
		}
	}

	@Override
	public void delete(Image entity) {
		try{
			getHibernateTemplate().delete(entity);
		}catch(HibernateException e){
			e.printStackTrace();
		}
	}

}
